// pages/my/myInvoice/myInvoiceDetail/myInvoiceDetail.js
const Toast = require("../../../../utils/notice.js").Toast;
Page({

    data: {
        invoice: {},
    },

    onLoad: function (options) {
        let invoiceStr = options.invoice;
        const invoice = JSON.parse(invoiceStr);
        this.setData({
            invoice: invoice,
        })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    downloadFile() {
        Toast.loading("文件下载中");

        let netPath = this.data.invoice.filePathArr[0];
        let localPath = wx.env.USER_DATA_PATH;
        const fileName = this.getFileName(netPath);
        let localFullPath = localPath + "/" + fileName;
        wx.downloadFile({
            url: netPath,
            filePath: localFullPath,
            timeout: 30 * 1000,
            success: function() {
                Toast.success("下载成功！");
            },
            fail: function() {
                Toast.fail("下载失败！");
            }
        })
    },

    getFileName(path="") {
        var pathArr = path.split("/");
        return pathArr[pathArr.length - 1];
    }

})